using UnityEngine;
using System.Collections;

public class Projectile : MonoBehaviour {
	
	public GameObject target;
	GameObject tower;
	float time;
	int ID;
	public static int IDCounter = 0;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		
		if (target != null)
		{
			//Debug.Log("shoot");
			Vector3 lerpPos = new Vector3();
			lerpPos = Vector3.Lerp(tower.transform.position, target.transform.position, time);
			transform.position = lerpPos;
			time += Time.deltaTime;
		}

		if (time > 1)
		{
			time = 0;
		}
	
	}
	
	public void SetTarget(GameObject tar, GameObject tow)
	{
		target = tar;
		tower = tow;
		time = 0;
	}

	void OnTriggerEnter(Collider c)
	{
		if (c.tag.Equals("Minion"))
		{
			Debug.Log(ID + " collided with minion");
			Destroy(gameObject);
			this.enabled = false;
			c.gameObject.GetComponent<Minion>().hp -= 50;
		}
	}

	public void SetID(int i)
	{
		ID = i;
		IDCounter++;
	}
}
